package com.yanqu.road.server.cmd.union.parergon;

import com.yanqu.road.pb.union.Parergon;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.union.UnionParergonMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

//@Cmd(code = Protocol.S_UNION_PARERGON_BARGAIN, desc = "砍价")
public class BragainCmd extends AbstractCommand {
    private int bussinessId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        Parergon.BargainReqMsg reqMsg = Parergon.BargainReqMsg.parseFrom(packet.getBytes());
        bussinessId = reqMsg.getBussinessId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (StringUtils.isNullOrEmpty(player.getUserInfo().getUnionUid())) {
            ret = GameErrorCode.E_PARERGON_NOT_IN_UNION;
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        Parergon.BargainRespMsg.Builder respMsg;
        if (ret!= 0) {
            respMsg = Parergon.BargainRespMsg.newBuilder();
            respMsg.setRet(ret);
        } else {
            respMsg = UnionParergonMgr.bargain(bussinessId, player.getUserId());
        }
        player.sendPacket(Protocol.U_UNION_PARERGON_BARGAIN, respMsg);
    }
}
